package org.osgi.demo.service;

import org.osgi.demo.say.SayHello;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;

public class Activator implements BundleActivator {
	private ServiceRegistration serviceReg = null;

	public void start(BundleContext context) throws Exception {

		SayHelloService sayService = new SayHelloService();

		serviceReg = context.registerService(SayHelloService.class.getName(),
				sayService, null);// 1

		ServiceReference serviceRef = context
				.getServiceReference(SayHello.class.getName());// 2

		sayService.setSay((SayHello) context.getService(serviceRef));// 2

		sayService.helloWorld();// 3
	}

	public void stop(BundleContext context) throws Exception {
		if (serviceReg != null)
			serviceReg.unregister();
	}

}
